package com.homelock.controller;


import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.homelock.domain.query.OpenRecordQuery;
import com.homelock.service.LockOpenRecordService;
import com.pi.base.dto.result.AppResult;
import com.pi.http.base.controller.BaseController;

@RequestMapping("/lock/door")
@RestController
public class LockOpenRecordController extends BaseController{
	private static final Logger logger = LoggerFactory.getLogger(LockOpenRecordController.class);

	private LockOpenRecordService lockOpenRecordService;
	
  @Autowired
  public LockOpenRecordController(LockOpenRecordService lockOpenRecordService){
    Assert.notNull(lockOpenRecordService, "锁具开门服务服务为空");
    this.lockOpenRecordService = lockOpenRecordService;
  }
  
	@RequestMapping("/record")
	public AppResult queryOpenDoorRecord(OpenRecordQuery openRecordQuery){
	  openRecordQuery.setOperateUserId(getLoginUserId());
		return AppResult.newSuccessResult(lockOpenRecordService.queryOpenRecordList(openRecordQuery));
	}

	@RequestMapping("/record/v2")
	public AppResult queryZxOpenDoorRecord(OpenRecordQuery openRecordQuery){
        openRecordQuery.setOperateUserId(getLoginUserId());
     	return AppResult.newSuccessResult(lockOpenRecordService.queryZxOpenRecordList(openRecordQuery));
	}

	@PostMapping(value = "/device/callback")
	public AppResult insertRecord(@RequestBody JSONObject recordObject){
	    logger.info("开始执行回调接口：insertRecord");
	    logger.info("回调参数："+recordObject.toJSONString());
	    boolean flag = lockOpenRecordService.insertLockOpenRecord(recordObject);
	    return AppResult.OK;


	}

}
